package org.fullhappy;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.*;

import org.fullhappy.dao.ArticleDAO;
import org.fullhappy.entity.Article;

@SuppressWarnings("serial")
public class Mini_tutorial_webServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");
		Article article = new Article();
		article.setTitle("title3" + req.getSession().getId());
		article.setDescription("description"+ req.getSession().getId());
		article.setCatalogId((byte)1);
		article.setContent("content"+req.getSession().getId());		
//		article.setCreateDate(new Date());
		ArticleDAO articleDAO = new ArticleDAO();
		try {
			articleDAO.insert(article);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		List<Article> articles = articleDAO.findAll();
		for (Article n : articles) {
			resp.getWriter().println(n.getArticleID() + "<br/>");
			resp.getWriter().println(n.getTitle() + "<br/>");
			resp.getWriter().println(n.getDescription() + "<br/>");
			if (n.getCreateDate() != null) {
				resp.getWriter().println(n.getCreateDate() + "<br/>");
			}
		}

	}
}
